 <%@page import="dao.LoaiTauDAO"%>
<%@page import="dto.LoaiTau"%>
<%@page import="dao.LoaiToaTauDAO"%>
<%@page import="dto.LoaiToaTau"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.List"%>
<%@page import="dto.Tau"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Quản Lý Tàu</title>
        <link href="css/tablestyle.css" type="text/css" rel="stylesheet" />
        <script language="javascript">
            function CheckAllQT(value)
            {
                var checks = document.getElementsByName('delete');
                var boxlength = checks.length;
                if(value == true)
                {
                    for(i=0; i< boxlength;i++)
                    {
                         checks[i].checked = true;
                    }
                }
                else
                {       
                    for(i=0; i< boxlength;i++)
                    {
                        checks[i].checked = false;
                    }
                }
            }
            function Confirm_Del()
            {
                if(confirm("Bạn có chắc muốn xóa không?") == true){
                    return true;
                }else{
                    return false;
                }
            }
            
            function submitWithHref(obj) {
                var theHref = obj.href;
                document.frmTau.action = theHref;
                document.frmTau.submit();
             }
        </script>
        
        
        <link href="css/jquery-ui.css" type="text/css" rel="stylesheet"/>
        <script src="js/jquery-1.9.1.js" type="text/javascript"></script>
        <script src="js/jquery-ui.js" type="text/javascript"></script>
      
    </head>
    <body>
       <%-- 
        <%
            if(session.getAttribute("USERNAME")==null){
                response.sendRedirect("Login");
            }else{
        %> --%>
       <% try { %>
        
        <div id="container">
            <%@include file="header.jsp" %>
        
        <div id="content">
        
            <%@include file="menu.jsp" %>
            
            <div id="contentpage">

            <form action="Tau" method="post" name="frmTau">
            <div id="titledata">
                <h>Toa Tàu</h>
                <div class="titleaction"><a class="btninsert" href="Tau?action=insert">Insert</a>
                    <input class="btndelete" name="action" type="submit" value="Delete" onclick="return Confirm_Del();" />
                </div>
            </div>
            <div id="contentdata">
            <% 
                List<Tau> dsnd = (List<Tau>) request.getAttribute("dsnd");
            %>

            <table class="tbdata">
                <tr class="title">
                    <td><input type="checkbox" name="checkall" onclick="CheckAllQT(checkall.checked);" /></td>
                    <td>Mã Tàu</td>
                    <td>Tên tàu </td>
                    <td>Hãng sản xuất</td>
                    <td>Ngày vận hành</td> 
                     <td>Số lượng toa</td> 
                    <td>Trạng thái</td>
                    <td>Loại tàu</td>
                    <td>Action</td>
                </tr>
               
                <%
               // int sotrang = (Integer)request.getAttribute("sotrang"); 
                for(int i =0; i < dsnd.size(); i++){
                %>
                <% if(i%2==0){ %>
                <tr class="even"> 
                    <% }else { %>
                <tr class="odd">
                   <% } %>
                    <td><input type="checkbox" name="delete" value="<%= dsnd.get(i).getMatau()%>" /></td>
                    <td><%= dsnd.get(i).getMatau()%></td>
                    <td><%= dsnd.get(i).getTendoantau()%></td>
                    <td><%= dsnd.get(i).getHangsanxuat()%></td>
                    <td><%= dsnd.get(i).getNgayvanhanh()%></td>
                     <td><%= dsnd.get(i).getSoluongtoa()%></td>
                    <td><% if(dsnd.get(i).getTrangthai() == 1){
                            out.print("Hiện");
                        } else{
                            out.print("Ẩn");
                        } %>
                    </td>
                    
                    
                           
                    <td>  <% List<LoaiTau> dslnd = (List<LoaiTau>) request.getAttribute("dslnd"); %>
                        <% 
                            if(dsnd.get(i).getMaloaitau()!= 0){
                            String  tenloainguoidung ="";
                            tenloainguoidung = LoaiTauDAO.LayThongTinLoaiTau(dsnd.get(i).getMaloaitau()).getTenloaitau();
                            out.print(tenloainguoidung);
                            }
                        %> 
                    </td>
                    <td>
                        <a class="btnview" href="Tau?action=view&id=<%= dsnd.get(i).getMatau()%>">View</a>
                        <a class="btnedit" href="Tau?action=edit&id=<%= dsnd.get(i).getMatau() %>">Edit</a>
                    </td>
                </tr>
                <% } %>
 
            </table>
          </div>   
            </form>
            </div>         
        </div>        
    </div>          
    <% } catch(Exception ex){ response.sendRedirect("fail.jsp"); } %>
    </body>
</html>
